{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "04ae8735",
   "metadata": {},
   "source": [
    "## 1. APP 现货行情-实时行情函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66efda23",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_bookTicker|获取一个产品的最优挂单|\n",
    "|get_bookTickers|获取全部产品的最优挂单（列表格式）|\n",
    "|get_bookTickersMap|获取全部产品的最优挂单 （字典格式）|\n",
    "|get_tickerPrice|获取一个产品的最新价格|\n",
    "|get_tickerPrices|获取全部产品的最新价格（列表格式）|\n",
    "|get_tickerPricesMap|获取全部产品的最新价格 (字典格式)|\n",
    "|get_depth|获取深度信息|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e04f3aff",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1dc4d213",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceSPOT\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0778ca72",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceSPOT = BinanceSPOT(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "market = binanceSPOT.market"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd83596d",
   "metadata": {},
   "source": [
    "## 3. 获取一个产品的最优挂单 get_bookTicker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "65f094c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'symbol': 'BTCUSDT',\n",
      "          'bidPrice': '40059.99000000',\n",
      "          'bidQty': '7.90103000',\n",
      "          'askPrice': '40060.00000000',\n",
      "          'askQty': '2.29840000'},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "bookTicker_result = market.get_bookTicker(symbol='BTCUSDT')\n",
    "eprint(bookTicker_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a8c0f89",
   "metadata": {},
   "source": [
    "## 4. 获取全部产品的最优挂单（列表格式）get_bookTickers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ae4a7d95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'symbol': 'ETHBTC',\n",
      "           'bidPrice': '0.05594000',\n",
      "           'bidQty': '4.35300000',\n",
      "           'askPrice': '0.05595000',\n",
      "           'askQty': '27.14070000'},\n",
      "          {'symbol': 'LTCBTC',\n",
      "           'bidPrice': '0.00164000',\n",
      "           'bidQty': '29.84500000',\n",
      "           'askPrice': '0.00164100',\n",
      "           'askQty': '45.26200000'},\n",
      "          {'symbol': 'BNBBTC',\n",
      "           'bidPrice': '0.00734300',\n",
      "           'bidQty': '3.71100000',\n",
      "           'askPrice': '0.00734400',\n",
      "           'askQty': '6.96100000'},\n",
      "          {'symbol': 'NEOBTC',\n",
      "           'bidPrice': '0.00026060',\n",
      "           'bidQty': '9.69000000',\n",
      "           'askPrice': '0.00026100',\n",
      "           'askQty': '5.80000000'},\n",
      "          {'symbol': 'QTUMETH',\n",
      "           'bidPrice': '0.00126800',\n",
      "           'bidQty': '638.00000000',\n",
      "           'askPrice': '0.00127300',\n",
      "           'askQty': '21.00000000'},\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "bookTickers_result = market.get_bookTickers()\n",
    "eprint(bookTickers_result, data_length=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "de17ac65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'symbol': 'BTCUSDT',\n",
      "           'bidPrice': '40062.06000000',\n",
      "           'bidQty': '1.67129000',\n",
      "           'askPrice': '40062.07000000',\n",
      "           'askQty': '5.59147000'},\n",
      "          {'symbol': 'ETHUSDT',\n",
      "           'bidPrice': '2241.25000000',\n",
      "           'bidQty': '63.64610000',\n",
      "           'askPrice': '2241.26000000',\n",
      "           'askQty': '70.79630000'}],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "bookTickers_result = market.get_bookTickers(symbols=['BTCUSDT', 'ETHUSDT'])\n",
    "eprint(bookTickers_result, data_length=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8862d8db",
   "metadata": {},
   "source": [
    "## 5. 获取全部产品的最优挂单 （字典格式）get_bookTickersMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "68083433",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'ETHBTC': {'symbol': 'ETHBTC',\n",
      "                     'bidPrice': '0.05593000',\n",
      "                     'bidQty': '20.92610000',\n",
      "                     'askPrice': '0.05594000',\n",
      "                     'askQty': '21.05760000'},\n",
      "          'LTCBTC': {'symbol': 'LTCBTC',\n",
      "                     'bidPrice': '0.00164000',\n",
      "                     'bidQty': '74.73600000',\n",
      "                     'askPrice': '0.00164200',\n",
      "                     'askQty': '388.14800000'},\n",
      "          'BNBBTC': {'symbol': 'BNBBTC',\n",
      "                     'bidPrice': '0.00734200',\n",
      "                     'bidQty': '4.53500000',\n",
      "                     'askPrice': '0.00734300',\n",
      "                     'askQty': '5.71400000'},\n",
      "          'NEOBTC': {'symbol': 'NEOBTC',\n",
      "                     'bidPrice': '0.00026060',\n",
      "                     'bidQty': '9.69000000',\n",
      "                     'askPrice': '0.00026100',\n",
      "                     'askQty': '5.80000000'},\n",
      "          'QTUMETH': {'symbol': 'QTUMETH',\n",
      "                      'bidPrice': '0.00126800',\n",
      "                      'bidQty': '1165.60000000',\n",
      "                      'askPrice': '0.00127300',\n",
      "                      'askQty': '21.00000000'},\n",
      "          'EOSETH': {'symbol': 'EOSETH',\n",
      "                     'bidPrice': '0.00030350',\n",
      "                     'bidQty': '2490.90000000',\n",
      "                     'askPrice': '0.00030480',\n",
      "                     'askQty': '406.80000000'},\n",
      "          '...': '......'},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "bookTickersMap_result = market.get_bookTickersMap()\n",
    "eprint(bookTickersMap_result, data_length=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9fcd678d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'BTCUSDT': {'symbol': 'BTCUSDT',\n",
      "                      'bidPrice': '40072.30000000',\n",
      "                      'bidQty': '9.14236000',\n",
      "                      'askPrice': '40072.31000000',\n",
      "                      'askQty': '1.19617000'},\n",
      "          'ETHUSDT': {'symbol': 'ETHUSDT',\n",
      "                      'bidPrice': '2242.69000000',\n",
      "                      'bidQty': '39.63170000',\n",
      "                      'askPrice': '2242.70000000',\n",
      "                      'askQty': '36.98430000'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "bookTickersMap_result = market.get_bookTickersMap(symbols=['BTCUSDT', 'ETHUSDT'])\n",
    "eprint(bookTickersMap_result, data_length=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35ea7a1c",
   "metadata": {},
   "source": [
    "## 6. 获取一个产品的最新价格 get_tickerPrice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "719d1866",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'data': {'symbol': 'BTCUSDT', 'price': '40077.30000000'}, 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "tickerPrice_result = market.get_tickerPrice(symbol='BTCUSDT')\n",
    "eprint(tickerPrice_result, data_length=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aed4b80a",
   "metadata": {},
   "source": [
    "## 7. 获取全部产品的最新价格（列表格式） get_tickerPrices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4f265672",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'symbol': 'ETHBTC', 'price': '0.05595000'},\n",
      "          {'symbol': 'LTCBTC', 'price': '0.00164000'},\n",
      "          {'symbol': 'BNBBTC', 'price': '0.00734200'},\n",
      "          {'symbol': 'NEOBTC', 'price': '0.00026090'},\n",
      "          {'symbol': 'QTUMETH', 'price': '0.00127200'},\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "tickerPrices_result = market.get_tickerPrices()\n",
    "eprint(tickerPrices_result, data_length=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9af607e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'symbol': 'BTCUSDT', 'price': '40066.02000000'}, {'symbol': 'ETHUSDT', 'price': '2242.38000000'}],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "tickerPrices_result = market.get_tickerPrices(symbols=['BTCUSDT', 'ETHUSDT'])\n",
    "eprint(tickerPrices_result, data_length=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8acb9ce",
   "metadata": {},
   "source": [
    "## 8. 获取全部产品的最新价格 (字典格式) get_tickerPricesMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d40d551a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'ETHBTC': {'symbol': 'ETHBTC', 'price': '0.05596000'},\n",
      "          'LTCBTC': {'symbol': 'LTCBTC', 'price': '0.00164000'},\n",
      "          'BNBBTC': {'symbol': 'BNBBTC', 'price': '0.00734300'},\n",
      "          'NEOBTC': {'symbol': 'NEOBTC', 'price': '0.00026090'},\n",
      "          'QTUMETH': {'symbol': 'QTUMETH', 'price': '0.00127200'},\n",
      "          'EOSETH': {'symbol': 'EOSETH', 'price': '0.00030480'},\n",
      "          '...': '......'},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "tickerPricesMap_result = market.get_tickerPricesMap()\n",
    "eprint(tickerPricesMap_result, data_length=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "92d26a9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'BTCUSDT': {'symbol': 'BTCUSDT', 'price': '40059.59000000'},\n",
      "          'ETHUSDT': {'symbol': 'ETHUSDT', 'price': '2241.78000000'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "tickerPricesMap_result = market.get_tickerPricesMap(symbols=['BTCUSDT', 'ETHUSDT'])\n",
    "eprint(tickerPricesMap_result, data_length=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fda118e7",
   "metadata": {},
   "source": [
    "## 9. 获取深度信息 get_depth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a8f03e2d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'lastUpdateId': 42417598490,\n",
      "          'bids': [['40067.99000000', '6.41848000'],\n",
      "                   ['40067.98000000', '3.41816000'],\n",
      "                   ['40067.75000000', '0.00021000'],\n",
      "                   ['40067.51000000', '0.00021000'],\n",
      "                   ['40067.27000000', '0.00021000'],\n",
      "                   '......'],\n",
      "          'asks': [['40068.00000000', '0.77779000'],\n",
      "                   ['40068.15000000', '0.03249000'],\n",
      "                   ['40068.19000000', '0.01972000'],\n",
      "                   ['40068.23000000', '0.00021000'],\n",
      "                   ['40068.33000000', '0.16291000'],\n",
      "                   '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "depth_result = market.get_depth(symbol='BTCUSDT')\n",
    "eprint(depth_result, data_length=5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
